package com.lagou.homework;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class HomeWorkDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //加载配置文件
        Configuration conf = new Configuration();
        //Job对象
        Job job = Job.getInstance(conf, "homeworkDriver");
        //指定jar
        job.setJarByClass(HomeWorkDriver.class);
        //指定Mapper和Reduce
        job.setMapperClass(HomeWorkMapper.class);
        job.setReducerClass(HomeWorkReducer.class);

        //指定Map端输出
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(NullWritable.class);

        //指定Reduce端输出
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);

        FileInputFormat.setInputPaths(job,new Path("E:\\data"));

        FileOutputFormat.setOutputPath(job,new Path("E:\\output"));

        //提交任务
        boolean flag = job.waitForCompletion(true);

        System.exit(flag ? 0 : 1);


    }
}
